package edu.gdkm.service.impl;

import edu.gdkm.dao.AccountDao;
import edu.gdkm.pojo.Account;
import edu.gdkm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    @Override
    public Account findAccountById(Integer id) {
        return accountDao.findAccountById(id);
    }

    @Override
    public int insertAccount(Account account) {
        return accountDao.insertAccount(account);
    }

    @Override
    @Transactional
    public void transfer(Account outUser, Account inUser, Double money) {
        outUser.setBalance(outUser.getBalance()-money);
        inUser.setBalance(inUser.getBalance()+money);
        accountDao.updateAccount(outUser);
        int i=1/0;
        accountDao.updateAccount(inUser);
    }
}
